﻿using BodaNetCommunications.Utilities.ComTypes;

namespace BodaNetCommunications.Cores
{
    public class ConnectionOptions
    {
        public ConnectionOptions()
        {

        }

        /// <summary>
        /// Mc的连接方式
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="plcType"></param>
        public ConnectionOptions(string? ip, int port, McPLCType plcType = McPLCType.McPlc)
        {
            Ip = ip;
            Port = port;
            PlcType = plcType;
        }

        /// <summary>
        /// Mc的连接方式
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="plcType"></param>
        public ConnectionOptions(string? ip, int port, byte rack, byte slot)
        {
            Ip = ip;
            Port = port;
            Rack = rack;
            Slot = slot;
        }

        /// <summary>
        /// Mc的连接方式
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="plcType"></param>
        public ConnectionOptions(string? ip, int port, string plcName)
        {
            Ip = ip;
            Port = port;
            PlcName = plcName;
        }

        public string? OptionName { get; set; }

        public string? Ip { get; set; }

        public int Port { get; set; }

        /// <summary>
        /// 机架号
        /// </summary>
        public byte Rack { get; set; }

        /// <summary>
        /// 槽位号
        /// </summary>
        public byte Slot { get; set; }

        /// <summary>
        /// 如果是Mc协议，则需要传入Plc类型，便于转换地址
        /// </summary>
        public McPLCType PlcType { get; set; }

        public int ReadTimeout { get; set; } = 1000;

        public int ConnectTimeout { get; set; } = 50;

        /// <summary>
        /// Plc的名称，比如S7-200Smart, S7-1200, S7-1500
        /// </summary>
        public string PlcName { get; set; }

        /// <summary>
        /// 大小端
        /// </summary>
        public EndianType EndianType { get; set; } = EndianType.DCBA;


        /// <summary>
        /// 从站地址
        /// </summary>
        public byte SlaveId { get; set; } = 1;

        /// <summary>
        /// Modbus有的地址从0开始，或者地址位需要加减1才行，实际地址减去这个数值为地址的偏移值
        /// </summary>
        public short FirstAddress { get; set; } = 0;

        /// <summary>
        /// 字符串是否反转
        /// </summary>
        public bool StringReverse { get; set; }


        /// <summary>
        /// 西门子的DB快是否优化，默认不要优化
        /// 优化过的DB，则采用小端
        /// </summary>
        public bool IsOptimized { get; set; } = false;
    } 
}
